package com.ce.pms.renovation.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.renovation.dao.IReinspectionDao;
import com.ce.pms.renovation.model.ReinspectionDO;

/**
*
* 功能描述: 竣工复验记录DAO ReinspectionDaoImpl
* <p>版权所有：中企动力
* <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
*
* @author  许心炜
* Created on：  2008-12-19
* @author  许心炜
* update on：  2008-12-19
*/

public class ReinspectionDaoImpl extends PmsBaseDaoImpl<ReinspectionDO> implements IReinspectionDao{

	/**
	 *根据验收申请ID获得竣工复验记录列表
	 *@author  许心炜
	 *@param inspectionRequisitionId - 装修验收申请ID
	 *@return 竣工复验记录列表
	 * */
	public List<ReinspectionDO> getReinspections(Long inspectionRequisitionId) {
		String hql = "from ReinspectionDO r where r.inspectionRequisition.keyword = ? ";
		Query query = this.createQuery(hql, inspectionRequisitionId);
		return  query.list();
	}

	/**
	 *根据ID获得竣工复验DO
	 *@author  许心炜
	 *@param inspectionRequisitionId - 装修申请ID
	 *@return ReinspectionDO
	 * */
	public ReinspectionDO getReinspection(Long inspectionRequisitionId) {
		String hql = "from ReinspectionDO r where r.inspectionRequisition.keyword = ? ";
		Query query = this.createQuery(hql, inspectionRequisitionId);

		if(query.list().size() > 0) {
			return  (ReinspectionDO) query.list().get(0);
		}else {
			return null;
		}
	}

	/** 功能描述: 根据许可证号获得通过的复验记录 <br>
	 * @param licenceId
	 * @return
	 * Create author:许心炜 <br>
	 * Create on:2009-1-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	public ReinspectionDO getPassReinspectionByLicenceId(Long licenceId) {
		String hql = "from ReinspectionDO r where r.inspectionRequisition.renovateLicence.keyword = ? and r.result='001' ";
		Query query = this.createQuery(hql, licenceId);

		if(query.list().size() > 0) {
			return  (ReinspectionDO) query.list().get(0);
		}else {
			return null;
		}
	}


}
